home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Dr. Windows 3
/
dr win3.zip
/
dr win3
/
DEMONSTR
/
ATEASY_2.ZIP
/
CDLL.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-08-01
|
8KB
|
200 lines
/****************************************************************************
PROGRAM: CDLL.c
BY : Ronnie Yazma, Copyright 1993 GEOTEST Inc.
PURPOSE: Demonstarte None ATEasy type DLL functions.
TO COMPILE:
Use CDLL.MAK when using Visual C/C++ v1.0 or MS-C 7.0
Use CDLL.PRJ when using Borland C/C++ v3.1
This file compiled in large memory model.
VERSION: 2.00 (Jul-26-93)
FUNCTIONS/SUBROUTINES:
- MaxSub() : finds the max between 2 floats
- MaxLongFunc() : return the max between 2 floats
- AverageArray() : find the avarage of float array
- NoSpaces() : delete leading & trailing spaces in a string
- UCase2Dim() : convert 2 dim string to upper case
COMMENTS:
When using None ATEasy type DLL the parameters are passed from ATEasy
in the following way:
ATEasy DLL Remarks
--------------------------------------------------------------------------
VAL Byte char BYTE also applicable
VAR Byte char FAR *
VAL Int short WORD also applicable (int and UINT in 16 bit DLLs)
VAR Int short FAR *
VAL Long long DWORD also applicable
VAR Long long FAR *
VAL Float double
VAR Float double FAR *
VAL/VAR String[] char FAR * or LPSTR null terminated string
VAL/VAR String[,] char FAR * FAR * (array of pointers to strings)
VAL/VAR xxx [] or [,] xxx FAR * (xxx is Byte/Int/Long/Float)
Note that the calling convention is PASCAL.
****************************************************************************/
#include <windows.h>
#include <string.h> // for memmove
#include <ctype.h> // for isspace, toupper
#define _CALLBACK FAR PASCAL __export
/****************************************************************************
FUNCTION: LibMain(HANDLE, WORD, WORD, LPSTR)
PURPOSE: Is called by LibEntry. LibEntry is called by Windows when
the DLL is loaded. The LibEntry routine is provided in
the LIBENTRY.OBJ in the SDK Link Libraries disk. (The
source LIBENTRY.ASM is also provided.)
LibEntry initializes the DLL's heap, if a HEAPSIZE value is
specified in the DLL's DEF file. Then LibEntry calls
LibMain. The LibMain function below satisfies that call.
The LibMain function should perform additional initialization
tasks required by the DLL. In this example, no initialization
tasks are required. LibMain should return a value of 1 if
the initialization is successful.
Some compilers vendors provides LibMain in their static libraries
so you're allowed not to include this function.
****************************************************************************/
int FAR PASCAL LibMain(HINSTANCE hInstance, WORD wDataSeg, WORD cbHeapSize, LPSTR lpszCmdLine)
{
return(1);
}
/****************************************************************************
FUNCTION: WEP(int)
PURPOSE: Performs cleanup tasks when the DLL is unloaded. WEP() is
called automatically by Windows when the DLL is unloaded (no
remaining tasks still have the DLL loaded). Some compilers vendors
provides WEP in their static libraries so you're allowed not to
include this function (if you don't need cleanup). If you're
using MS-C it is much safer to use _WEP instead of WEP .
The WEP should return 1.
****************************************************************************/
int FAR PASCAL WEP(int nExitType)
{
return(1);
}
/****************************************************************************
FUNCTION: MaxSub(dX1, dX2, lpdResult)
PURPOSE: Finds the max of 2 floats (dX1 & dX2) into lpdResult.
This subroutine defined in ATEasy as:
Max(fX1: VAL FLOAT, fX2: VAL FLOAT, fResult: VAR FLOAT): SUB DLL
****************************************************************************/
void _CALLBACK MaxSub(double dX1, double dX2, double FAR * lpdResult)
{
*lpdResult=dX1 > dX2 ? dX1 : dX2;
}
/****************************************************************************
FUNCTION: MaxLongFunc(dX1, dX2)
PURPOSE: Returns the max of 2 longs (lX1 & lX2).
Note that this is a function.
This function defined in ATEasy as:
Long Max(lX1: VAL LONG, lX2: VAL LONG): Function DLL
****************************************************************************/
long _CALLBACK MaxLongFunc(long lX1, long lX2)
{
return lX1 > lX2 ? lX1 : lX2;
}
/****************************************************************************
FUNCTION: AverageArray(lpdNumbers, nCount, lpdResult)
PURPOSE: Calculate the mean value of lpdNumbers array into lpdResult.
This function defined in ATEasy as:
AverageArray(afNumbers : VAL FLOAT[], iCount : VAL Int, dResult : VAR FLOAT) : SUB DLL
****************************************************************************/
VOID _CALLBACK AverageArray(double FAR * lpdNumbers, short nCount, double FAR * lpdResult)
{
double dResult=0.0;
short i;
for (i=0; i < nCount; i++)
dResult+=lpdNumbers[i];
if (nCount)
dResult/=nCount;
*lpdResult=dResult;
}
/****************************************************************************
FUNCTION: NoSpaces(lpsz)
PURPOSE: Delete leading & trailing spaces in a string
This function defined in ATEasy as:
NoSpaces(s : VAR String)
****************************************************************************/
VOID _CALLBACK NoSpaces(LPSTR lpsz)
{
short i, j;
for (i=strlen(lpsz); i > 0; i--) // delete trailing spaces
if (!isspace(lpsz[i-1])) break;
lpsz[i]=0;
for (j=0; j < i; j++) // delete leading spaces
if (!isspace(lpsz[j])) break;
if (j) // move to start
memmove(lpsz, lpsz+j, strlen(lpsz));
}
/****************************************************************************
FUNCTION: UCase2Dim(lppsz, nCount)
PURPOSE: convert 2 dim string to upper case
nCount hold number of strings.
This function defined in ATEasy as:
UCase2Dim(asStrings : VAR String[,], iCount VAL Int)
****************************************************************************/
VOID _CALLBACK UCase2Dim(char FAR * FAR * lppsz, short nCount)
{
short i, j, nLen;
LPSTR lp;
for (i=0; i < nCount; i++)
{ lp=lppsz[i]; // get the i string
nLen=strlen(lp); // get the string length
for (j=0; j < nLen; j++)
lp[j]=toupper(lp[j]); // convert to upper case
}
}
/****************************************************************************
E - O - F
****************************************************************************/